/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================timeCard 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    timeTrackData:{} //打卡数据
  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    /**
     *查询打卡面板
     * @param commit
     * @param paramData = {}
     * @returns {Promise}
     */
    getTimeTrack({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/card',
          data:paramData,
          success:function (data) {
            console.log(data)
            commit('setCommonStateData',{key:'timeTrackData',data:data.data});
            resolve(data);
          }
        })
      })
    },
    clockIn({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/clock/in',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    clockOut({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/clock/out',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     * 接口名称：Break休息 请求URL：time/track/break/start
     * @param commit
     * @param paramData{id	Break Id	Number}
     * @returns {Promise}
     */
    breakStart({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/break/start',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    /**
     *
     * @param commit
     * @param paramData {id}
     * @returns {Promise}
     */
    breakEnd({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/track/break/end',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    }
  },
  getters: {
    //打卡数据
    timeTrackData:(state, getters)=> {
      return state.timeTrackData;
    }
  }
}
